<template>
	<view class="content">

		<view class="box">
			<view class="boxinput">
				账号：<input type="text" v-model="userInfo.account" placeholder="手机号" />
			</view>
			<view class="boxinput">
				密码： <input type="text" v-model="userInfo.password" />
			</view>
			<view class="boxLogin" @click="login">
				登录
			</view>
			<view class="boxLogin" @click="signIn">
				注册
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					account: null,
					password: null
				}
			}
		},
		onLoad() {

		},
		methods: {
			async signIn() {
				const res = await uniCloud.importObject('login').signIn(this.userInfo)
				if (res.code == 201) {
					uni.showToast({
						title: '此账号已注册',
						icon: 'none'
					})
				} else {
					uni.showToast({
						title: '注册成功',
						icon: 'none'
					})
					uni.setStorageSync('userInfor', res)
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
			},
			async login() {
				const res = await uniCloud.importObject('login').login(this.userInfo)
				if (res.code == 200) {
					uni.showToast({
						title: '登录成功',
						icon: 'none'
					})
					uni.setStorageSync('userInfor', res)
					uni.navigateBack()


				} else {
					uni.showToast({
						title: '账号或密码错误',
						icon: 'none'
					})
				}
			}

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

	}

	.box {

		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		margin-top: 200rpx;

	}

	.boxinput {
		color: #5d5d5d;
		width: 500rpx;
		margin-top: 12rpx;
		background-color: #ececec;
		display: flex;
		align-items: center;
		padding: 15rpx 20rpx;
		border-radius: 10rpx;
	}

	.boxLogin {
		margin-top: 60rpx;
		padding: 20rpx 60rpx;
		background-color: #1b8cf5;
		color: #fff;
		border-radius: 15rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
		color: #00aa7f;
	}
</style>